import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:jinke/page/pro_list/subs/pro_detail/subs/pro_instruction/widgets/cell.dart';
import 'package:jinke/page/pro_list/subs/pro_detail/subs/pro_instruction/widgets/new_cell.dart';
import 'package:jinke/utils/component/page_state/widgets/empty.dart';

import '../../../../../../entrance/route/routes.dart';
import 'index.dart';

class ProInstructionPage extends StatelessWidget {
  ProInstructionPage(this.proId){
    controller.state.proId = proId;
    controller.initData();
  }
  String proId='';
  final controller = Get.put(ProInstructionController());
  // 主视图
  Widget _buildView() {
    return controller.state.lists.length==0?EmptyView():ListView.builder(
      itemBuilder: ((context, index) {
        // if (index == 0) {
        //   return InstructionNewCell();
        // }
        return InstructionCell(controller.state.lists[index]);
      }),
      itemCount: controller.state.lists.length,
    );
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder<ProInstructionController>(
      builder: (_) {
        return Scaffold(
          body: SafeArea(
            child: _buildView(),
          ),
          floatingActionButtonLocation:
          FloatingActionButtonLocation.centerDocked,
          floatingActionButton: Container(
            margin: EdgeInsets.only(bottom: 80.r),
            alignment: Alignment.bottomRight,
            child: InkWell(
              onTap: () {
                Get.toNamed(RouterPath.make_instructionPage,arguments: controller.state.proId)!.then((value) {
                  if (value==true) {
                    controller.initData();
                  }
                });
              },
              child: Container(
                width: 93.r,
                height: 40.r,
                alignment: Alignment.center,
                decoration: BoxDecoration(
                  gradient: const LinearGradient(
                    colors: [
                      Color(0xff00A9FE),
                      Color(0xff0173FE),
                    ],
                    begin: Alignment.centerLeft,
                    end: Alignment.centerRight,
                  ),
                  borderRadius: BorderRadius.horizontal(
                    left: Radius.circular(20.r),
                  ),
                ),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    Icon(
                      Icons.add,
                      color: Colors.white,
                      size: 20.r,
                    ),
                    Text(
                      '作批示',
                      style: TextStyle(color: Colors.white, fontSize: 15.r),
                    )
                  ],
                ),
              ),
            ),
          ),
        );
      },
    );
  }
}
